package com.weita.lightfood.controller;


import com.weita.lightfood.model.entity.Material;
import com.weita.lightfood.model.vo.material.AddDishMaterialVo;
import com.weita.lightfood.service.MaterialService;
import com.weita.lightfood.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author IT_Monster at 2019/03/31 13:31.
 * 食材数据接口
 */
@Api(tags = "食材管理接口")
@RestController
@RequestMapping("/material")
public class MaterialController {
    @Autowired
    private MaterialService materialService;


    /**
     * 添加食材
     * @param material
     * @return
     */
    @ApiOperation("添加食材")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "calorie", value = "食材卡路里", defaultValue = "0"),
            @ApiImplicitParam(name = "type", value = "食材种类", defaultValue = "0")
    })
    @PostMapping("/addMaterial")
    public Result<Material> addMaterial(Material material) {
        try {
            return Result.success(materialService.addMaterial(material));
        } catch (Exception e) {
            System.out.println("添加食材出错");
            return Result.fail("添加食材出错");
        }
    }

    /**
     * 获取所有蔬菜水果类食材
     * @return
     */
    @ApiOperation("获取所有蔬菜水果类食材")
    @PostMapping("/getAllVegetables")
    public Result<List<AddDishMaterialVo>> getAllVegetables(){
        try {
            return Result.success(materialService.getAllVegetables());
        } catch (Exception e) {
            System.out.println("获取所有蔬菜水果类食材出错");
            return Result.fail("获取所有蔬菜水果类食材失败");
        }
    }

    /**
     * 获取所有肉类谷物坚果食材
     * @return
     */
    @ApiOperation("获取所有肉类谷物坚果食材")
    @PostMapping("/getAllMeats")
    public Result<List<AddDishMaterialVo>> getAllMeats(){
        try {
            return Result.success(materialService.getAllMeats());
        } catch (Exception e) {
            System.out.println("获取所有肉类谷物坚果食材出错");
            return Result.fail("获取所有肉类谷物坚果食材失败");
        }

    }

    /**
     * 获取所有佐料类食材
     * @return
     */
    @ApiOperation("获取所有佐料类食材")
    @PostMapping("/getAllSeasoning")
    public Result<List<AddDishMaterialVo>> getAllSeasoning() {
        try {
            return Result.success(materialService.getAllSeasoning());
        } catch (Exception e) {
            System.out.println("获取所有佐料类食材出错");
            return Result.fail("获取所有佐料类食材失败");
        }
    }

    /**
     * 商家端获取精选食材名
     * @return
     */
    @ApiOperation("获取精选食材名")
    @PostMapping("/getChoicenessMaterialName")
    public Result<List<String>> getChoicenessMaterialName() {
        try {
            return Result.success(materialService.getChoicenessMaterialName());
        } catch (Exception e) {
            System.out.println("获取精选食材名出错");
            return Result.fail("获取精选食材名失败");
        }
    }

    /**
     * 通过食材名获取卡路里
     * @param materialName
     * @return
     */
    @ApiOperation("通过食材名获取卡路里")
    @PostMapping("/getCalorieByMaterialName")
    public Result<String> getCalorieByMaterialName(String materialName){
        return Result.success(materialService.getCalorieByMaterialName(materialName));
    }

}
